package com.weixing.mall.provider.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weixing.mall.base.constant.GlobalConstant;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.model.query.MemberMessageQuery;
import com.weixing.mall.provider.model.vo.AdminMemberMessageVo;
import com.weixing.mall.provider.service.IMemberMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author c
 * @Date 2020-4-11 19:24:48
 * @Version 1.0
 */
@Validated
@RestController
@RequestMapping("admin/memberMessage")
@Api(value = "后端:会员消息管理", tags = "后端:会员消息管理")
public class AdminMemberMessageController extends BaseController {
    @Autowired
    private IMemberMessageService memberMessageService;

    @ApiOperation(value = "加载会员消息列表")
    @GetMapping("")
    public Result<IPage<AdminMemberMessageVo>> list(@SysInfo SysAuth auth, MemberMessageQuery memberMessageQuery) {
        if(auth.getUr().contains(GlobalConstant.RoleCode.KF) && auth.getUr().length() == GlobalConstant.RoleCode.KF.length()){//仅当是客服并且只有一个身份的时候做数据筛选
            memberMessageQuery.setCreatedBy(auth.getUid());
        }
        return ResultUtil.success(memberMessageService.selectMemberMessageList(initMpPage(),memberMessageQuery));
    }

    @ApiOperation(value = "会员消息删除")
    @GetMapping("del/{id}")
    public Result selectDetail(@PathVariable Long id){
        return memberMessageService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }

}
